package com.nbwyctf.helper.utils;

import java.util.regex.Pattern;

/**
 * @author chetaifu
 */
public class ValidUtil {
    private static final String MAIL_REGEX_PATTERN = "^(?=.{1,64}@)[A-Za-z0-9_-]+(\\.[A-Za-z0-9_-]+)*@[^-][A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$";

    private static final String PHONE_REGEX_PATTERN = "^((13[0-9])|(14[0,1,4-9])|(15[0-3,5-9])|(16[2,5,6,7])|(17[0-8])|(18[0-9])|(19[0-3,5-9]))\\d{8}$";

    public static boolean validateMail(String mailAddress) {
        return patternMatches(mailAddress, MAIL_REGEX_PATTERN);
    }

    public static boolean validateMobilePhone(String mobilePhoneNo) {
        return patternMatches(mobilePhoneNo, PHONE_REGEX_PATTERN);
    }

    private static boolean patternMatches(String content, String regexPattern) {
        return Pattern.compile(regexPattern)
                .matcher(content)
                .matches();
    }
}
